package sealte.hvpms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sealte.hvpms.dao.UserDAO;
import sealte.hvpms.dao.impl.UserDAOImpl;
import sealte.hvpms.pojo.UserCreate;

public class UCResetInfo extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		UserCreate uc = (UserCreate)request.getSession().getAttribute("UserCreate");
		if(uc!=null){
			String email = request.getParameter("email");
			String id_str = request.getParameter("id");
			if(email!=null&&id_str!=null){
				int id = Integer.parseInt(id_str);
				UserDAO ub = new UserDAOImpl();
				boolean flag = ub.resetEmail(id, email);
				String message = "";
				if(flag){
					message = "修改邮箱成功";
				}else{
					message = "修改失败，请联系管理员";
				}
				request.setAttribute("message_resetInfo", message);
				request.getRequestDispatcher("home/resetInfo.jsp").forward(request, response);
			}else{
				out.println("系统出错");
			}
		}else{
			out.println("谢绝跨路径访问");
		}
		
	}

}
